from myelin.Ns import MYELINS
from nodetypes.formats.mml.Events import Form


class Form(Form):
    
    def createInstance(self, context, node):
        args = context.request.args
        
        nxa = node.xml_append
        nxc = node.xml_create_element
        
        nxa(
            nxc(
                u'a:nick', MYELINS,
                content = args.has_key('nick') and unicode(args.pop('nick')[0])
            )
        )
        nxa(
            nxc(
                u'a:passwd', MYELINS
            )
        )
        
        # domain
        context.nodeType.createDomainOptions(
            context,
            nxa(
                nxc(
                    u'a:domain', MYELINS
                )
            ),
            args.has_key('domain') and unicode(args.pop('domain')[0])
        )
                    
        defaults = context.defaults
        nxa(
            nxc(
                u'a:session-ttl', MYELINS,
                attributes = {
                    u'value'    : defaults.session_ttl,
                    u'max'      : defaults.max_session_ttl,
                    u'increment': defaults.session_ttl,
                }
            )
        )
        
        return node